#include <iostream>
#include <memory>
using namespace std;
//产品基类
class Product
{
public:
    explicit Product(){};
    virtual ~Product(){};
    virtual void Run() = 0;

};
class ProductA :public Product
{
    void Run() override{
           cout<<"run A..."<<endl;
    }
};
class ProductB :public Product
{
    void Run() override{
           cout<<"run B..."<<endl;
    }
};
class ProductC :public Product
{
    void Run() override{
           cout<<"run C..."<<endl;
    }
};

//工厂基类
class Factory
{
public:
    explicit Factory(){};
    virtual ~Factory(){};
    virtual unique_ptr<Product>CreatProduct() = 0;
};
//工厂子类
class FactoryA:public  Factory
{
    unique_ptr<Product>CreatProduct()
    {
        cout<<"Factory A..."<<endl;
        return make_unique<ProductA>();
    }
};
//工厂子类
class FactoryB:public  Factory
{
    unique_ptr<Product>CreatProduct()
    {
        cout<<"Factory B..."<<endl;
        return make_unique<ProductB>();
    }
};
//工厂子类
class FactoryC:public  Factory
{
    unique_ptr<Product>CreatProduct()
    {
        cout<<"Factory C..."<<endl;
        return make_unique<ProductC>();
    }
};
int main()
{
    cout << "Hello World!" << endl;
    //每个产品由对应的工厂子类创建, 工厂父类只提供创建接口出来

    {
        Factory * fac = new FactoryA;
        unique_ptr ProDuct = fac->CreatProduct();
        ProDuct->Run();
    }


    {
        Factory * fac = new FactoryB;
        unique_ptr ProDuct = fac->CreatProduct();
        ProDuct->Run();
    }

    {
        Factory * fac = new FactoryC;
        unique_ptr ProDuct = fac->CreatProduct();
        ProDuct->Run();
    }

    return 0;
}
